import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

public class Bounce extends Applet implements ActionListener {

	Panel p;
	Image img;
	Vector<Bounce> v;

	public Bounce(Bounce bounce, Image img2) {

	}

	public void init() {
		Button b = new Button("Start");
		b.addActionListener(this);
		setLayout(new BorderLayout());
		add("North", b);
		add("Center", p = new Panel());
		p.setLayout(null);
		String imgName = getParameter("imagefile");
		if (imgName == null)
			imgName = "duke.gif";
		img = getImage(getCodeBase(), imgName);
		MediaTracker mt = new MediaTracker(this);
		mt.addImage(img, 0);
		try {
			mt.waitForID(0);
		} catch (InterruptedException e) {
			throw new IllegalArgumentException(
					"InterruptedException while loading image " + imgName);
		}
		if (mt.isErrorID(0)) {
			throw new IllegalArgumentException("Couldn't load image " + imgName);
		}
		v = new Vector<Bounce>();
	}

	public void actionPerformed(ActionEvent e) {
		System.out.println("Creat-ing another one!");
		Bounce s = new Bounce(this, img);
		p.add(s);
		v.addElement(s);
	}

	public void stop() {
		for (int i = 0; i < v.size(); i++) {
			((Bounce) (v.get(i))).stop();
		}
		v.clear();
	}
}